EinhugurJWT.Decode Method
Decodes and validates JSON Web Token.
Parameters
- params
- Parameters to specify how to decode and what to validate.
- getClaims
- Set to true if also wanting to get claims.
Returns
- EinhugurJWT.JWTResult
- JWTResult instance or exception is thrown.
Remarks
This function can throw JWTException.
try
var params as new EinhugurJWT.DecodingParameters()
params.Algorithm = EinhugurJWT.Algorithm.HS512
params.JWT =TextArea1.Text
params.VerificationKey = "Some SupER s3kret HMAC keY"
params.ValidateSubject = "Bjorn Eiriksson"
params.ValidateIssuer = "Einhugur"
params.ValidateExpiration = true
params.ExpirationToleranceSeconds = 60
params.ValidateIssuedAt = true
params.IssuedAtToleranceSeconds = 60
var result as EinhugurJWT.JWTResult = EinhugurJWT.Decode(params, true)
if result.ValidationResult = result.ResultValid then
MessageBox "Token is valid."
for each claim as EinhugurJWT.Claim in result.Claims
MessageBox claim.Key + " - " + claim.Value
next
else
if (result.ValidationResult and result.ResultTokenIsExpired) = result.ResultTokenIsExpired then
MessageBox "Token has expired."
end if
if (result.ValidationResult and result.ResultTokenIsNotYetValid) = result.ResultTokenIsNotYetValid then
MessageBox "The token is not yet valid."
end if
if (result.ValidationResult and result.ResultTokenNotIssuedYet) = result.ResultTokenNotIssuedYet then
MessageBox "The token has not been issued yet, are you from the future?"
end if
if (result.ValidationResult and result.ResultAudienceClaimInvalid) = result.ResultAudienceClaimInvalid then
MessageBox "The audience claim is invalid."
end if
if (result.ValidationResult and result.ResultIdClaimInvalid) = result.ResultIdClaimInvalid then
MessageBox "The JWT ID claim is invalid."
end if
if (result.ValidationResult and result.ResultIssuerClaimInvalid) = result.ResultIssuerClaimInvalid then
MessageBox "The issuer claim is invalid."
end if
if (result.ValidationResult and result.ResultSignatureVerificationFailure) = result.ResultSignatureVerificationFailure then
MessageBox "The token was potentially tampered with: its signature couldn't be verified."
end if
if (result.ValidationResult and result.ResultSubjectClaimInvalid) = result.ResultSubjectClaimInvalid then
MessageBox "The subject claim is invalid."
end if
if (result.ValidationResult and result.ResultTypeClaimFailure) = result.ResultTypeClaimFailure then
MessageBox "The token's ""typ"" claim validation failed."
end if
end if
catch ex as EinhugurJWT.JWTException
MessageBox(ex.Message)
end try
Supported Platforms:
macOS Intel 64 bitmacOS Apple SiliconWindows 32 bitWindows 64 bitWindows ARM 64 bitLinux 32 bitLinux 64 bitLinux ARM 32 bitLinux ARM 64 bitiOS
See Also
EinhugurJWT Module